﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace SimpleReminder
{
    public class EventHourly : EventBase
    {
        public EventHourly(DataRow dr)
            : base(dr)
        {
            if (base.Type != MyEvents.EventTypes.Hourly)
                throw new MyEvents.InvalidEventTypeException();
        }

        public override bool IsTimeToRun()
        {
            DateTime now = DateTime.Now;
            if (base.CanRun && 
                (now - base.LastRunTime).TotalHours >= base.Frequence && 
                StartDate.Minute == now.Minute &&
                Math.Floor((now - StartDate).TotalHours) % base.Frequence == 0
                )
            {
                return true;
            }
            return false;
        }
    }
}
